---
title: "Regression (Period-based) CLEAN"
editor: visual
format:
html:
embed-resources: true
toc: true
toc-depth: 4
toc-expand: 4
toc-title: Contents
html-math-method: katex
css: styles.css
code-fold: true
code-tools: true
code-overflow: scroll
code-line-numbers: true
code-copy: false
code-link: true
grid:
body-width: 1400px
sidebar-width: 200px
margin-width: 250px
---
## Intro
Here we provide exploration of LMER models fitted to the 2020 U.S. Congressional election Twitter Dataset (<https://doi.org/10.6084/m9.figshare.25523734>).
This document was ~~typeset~~ assembled using Quarto (<https://quarto.org>).
## Initialize Workspace {.collapse}
### Clear and Init Workspace
```{r}
#| echo: false
#| results: 'hide'
#| message: false
#| warning: false
#| error: false
#| collapse: true
rm(list = ls())
source("./helpers/helpers.R")
set.w(222)
```
### Imports
```{r}
#| results: 'hide'
#| message: false
#| warning: false
#| error: false
#| collapse: true
library(ggplot2)
library(GGally)
library(plyr)
library(tidyverse)
```
### Set Directories
```{r}
#| echo: false
#| results: 'hide'
#| message: false
#| warning: false
#| error: false
#| collapse: true
ifd0 <- "./data/i0002-aggregated/"
ofd0 <- "./data/j1001-data-inspection/"
dir.create(ofd0, showWarnings = FALSE, recursive = TRUE)
cat0(ifd0)
cat0(ofd0)
```
## Data Load and Inspection {.collapse}
### Data Load
```{r}
ifn0 <- "i0001-politicians-aggregated.rds"
suppressWarnings(rm(list = ls(pattern = "^df")))
df0 <- readr::read_rds(file.path(ifd0, ifn0)) %>%
dplyr::select(Name, Party, Outcome, Period, Time, Days, Agency) %>%
dplyr::mutate(
Period = forcats::fct_recode(
Period,
PC = "MI",
PB = "BE",
PA = "AR")) %>%
identity()
df0 %>% dim() %>% cat0()
for (name in names(df0)) {cat0(paste0(" ", name, ", "))}
```
### Skim
```{r}
set.w(222)
library(skimr)
options(scipen=999)
skimr::skim_format(numeric=list(digits=6))
## digits=4, scientific = FALSE
df0 %>% skimr::skim() %>% dplyr::select(-c(n_missing)) %>% print(numeric=list(digits=2))
```
### Check factors order
```{r}
df2 <- df0
df3 <- df0
summary(df0$Period)
df2$Period <- factor(df2$Period, levels = c("PB", "PC", "PA"))
summary(df2$Period)
df3$Period <- relevel(df0$Period, ref = "PB")
summary(df3$Period)
```
## Prepare for Regression {.collapse}
### File names and output directories
```{r}
#| echo: false
#| collapse: true
source("./helpers/helpers2.R")
```
### Stuff for plotting
```{r}
#| echo: false
#| results: 'hide'
#| message: false
#| warning: false
#| error: false
#| collapse: true
source("./helpers/helpers3.R")
```
### Marginalization
```{r}
#| echo: false
#| results: 'hide'
#| message: false
#| warning: false
#| error: false
#| collapse: true
options(ggeffects_margin = "mean_reference") ## DEFAULT
options(ggeffects_margin = "marginalmeans")
options(ggeffects_margin = "mean_mode")
options(ggeffects_margin = "empirical")
```
### Checkups
```{r}
#| echo: false
#| results: 'hide'
#| message: false
#| warning: false
#| error: false
#| collapse: true
suppressWarnings(rm(list = ls(pattern = "(^fit)|(^model.*)|(^Model.*)")))
REML <- TRUE
control <- lme4::lmerControl(optimizer = "Nelder_Mead")
for (var0 in ls(pattern = "(^df.*)|(^data.*)")) {
cat0(var0)
}
for (var0 in ls(pattern = "(^fit.*)|(^m.*)")) {
cat0(var0)
}
```
### Save data frame for reference
```{r}
file <- file.path(dir8, "data-df0.rds")
df0 %>% readr::write_rds(file)
cat0(file)
```
## Model 01: Null
### Fit
```{r}
model <- "fit01aPd"
suppressWarnings(rm(list = model))
assign(
model,
lmerTest::lmer(
formula = Agency ~ (1 | Name) + 1,
data = df0,
REML = REML,
control = control))
fbase <- file.path(dir8, model); write_model_info(fbase)
readr::write_rds(get(model), file = paste0(fbase, ".mdl.rds"))
pp(model); summary(get(model)) %>% print(correlation = TRUE)
cat0(sep2); pp(model); performance::r2(get(model))
cat0(sep2); pp(model); performance::icc(get(model))
cat0(sep2); pp(model); performance::icc(get(model), by_group = TRUE)
```
### Random Effects
```{r}
extra <- "9001"
terms <- "NONE"
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(get(model), type="re")
file = file.path(dir8, paste0(model,"-xtr-",extra,"-random-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=4, height=88, limitsize = FALSE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-random-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=4, height=88, limitsize = FALSE)
gg88
```
## Model 02: Time
### Fit
```{r}
model <- "fit02aPd"
suppressWarnings(rm(list = model))
assign(
model,
lmerTest::lmer(
formula = Agency ~ (Time | Name) + Time,
data = df0,
REML = REML,
control = control))
fbase <- file.path(dir8, model); write_model_info(fbase)
readr::write_rds(get(model), file = paste0(fbase, ".mdl.rds"))
pp(model); summary(get(model)) %>% print(correlation = TRUE)
cat0(sep2); pp(model); performance::r2(get(model))
cat0(sep2); pp(model); performance::icc(get(model))
cat0(sep2); pp(model); performance::icc(get(model), by_group = TRUE)
```
### Model Summary
```{r}
## pp(model);
tbl0 <- gtsummary::tbl_regression(
get(model),
add_pairwise_contrasts = TRUE,
exponentiate = FALSE,
tidy_fun = broom.mixed::tidy,
)
tbl0
```
### Model Parameters
```{r}
pp(model);
parameters::model_parameters(get(model))
```
### Plot Model: Estimates
```{r}
extra <- "0000"
terms <- "NONE"
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(get(model), type="est")
gg88 <- gg88 + ggplot2::ylim(-0.1,0.1) + line2 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-estimates-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-estimates-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Time
```{r}
terms <- c("Time")
extra <- "0001"
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### EF: Time
#### NULL: Time
```{r}
extra <- "1001"
terms <- c("Time")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
pp(model);
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Time
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.15,)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
## gg88 <- gg88 + coord_cartesian(ylim = c(0.45, 0.55))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
### Random Effects
```{r}
extra <- "9001"
terms <- "NONE"
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(get(model), type="re")
file = file.path(dir8, paste0(model,"-xtr-",extra,"-random-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=4, height=88, limitsize = FALSE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-random-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=4, height=88, limitsize = FALSE)
gg88
```
####
## Model 03: Time x Period
### Fit
```{r}
model <- "fit03aPd"
suppressWarnings(rm(list = model))
assign(
model,
lmerTest::lmer(
formula = Agency ~ (Time | Name) + Time * Period,
data = df0,
REML = REML,
control = control))
fbase <- file.path(dir8, model); write_model_info(fbase)
readr::write_rds(get(model), file = paste0(fbase, ".mdl.rds"))
pp(model); summary(get(model)) %>% print(correlation = TRUE)
cat0(sep2); pp(model); performance::r2(get(model))
cat0(sep2); pp(model); performance::icc(get(model))
cat0(sep2); pp(model); performance::icc(get(model), by_group = TRUE)
```
### Model Summary
```{r}
pp(model);
tbl0 <- gtsummary::tbl_regression(
get(model),
add_pairwise_contrasts = TRUE,
exponentiate = FALSE,
tidy_fun = broom.mixed::tidy,
)
tbl0
```
### Model Parameters
```{r}
pp(model);
parameters::model_parameters(get(model))
```
### Plot Model: Estimates
```{r}
pp(model)
extra <- "0000"
terms <- "NONE"
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(get(model), type="est")
gg88 <- gg88 + ggplot2::ylim(-0.3,0.3) + line2 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-estimates-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-estimates-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Time
```{r}
pp(model);
extra <- "0001"
terms=c("Time")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Period
```{r}
pp(model);
extra <- "0002"
terms=c("Period")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + stuff0
gg88$data$x <- c(2,1,3)
gg88 <- gg88 + scale_x_continuous(breaks=c(1,2,3), labels=c("PB", "PC", "PA"))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Time x Period
```{r}
pp(model);
extra <- "0003"
terms=c("Time", "Period")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + line0 + line1 + stuff0 + rect2
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### EF: Time
#### NULL: Time
```{r}
pp(model)
extra <- "1001"
terms <- c("Time")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Time
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05,)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
## gg88 <- gg88 + coord_cartesian(ylim = c(0.25, 0.75))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
### EF: Period
#### NULL: Period
```{r}
pp(model);
extra <- "1002"
terms <- c("Period")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Period
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
## gg88 <- gg88 + line0 + line1 + time0 + stuff0
gg88 <- gg88 + stuff0
gg88$data$x <- c(2,1,3)
gg88 <- gg88 + scale_x_continuous(breaks=c(1,2,3), labels=c("PB", "PC", "PA"))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
#### DIFF: Period
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### EF: Time x Period
#### NULL: Time x Period
```{r}
pp(model);
extra <- "1003"
terms <- c("Time", "Period")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Time x Period
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
gg88 <- gg88 + rect2
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
#### DIFF: Time x Period
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.docx"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
## Model 04: Time x Period x Outcome
### Fit
```{r}
model <- "fit04aPd"
suppressWarnings(rm(list = model))
assign(
model,
lmerTest::lmer(
formula = Agency ~ (Time | Name) + Time * Period * Outcome,
data = df0,
REML = REML,
control = control))
fbase <- file.path(dir8, model); write_model_info(fbase)
readr::write_rds(get(model), file = paste0(fbase, ".mdl.rds"))
pp(model); summary(get(model)) %>% print(correlation = TRUE)
cat0(sep2); pp(model); performance::r2(get(model))
cat0(sep2); pp(model); performance::icc(get(model))
cat0(sep2); pp(model); performance::icc(get(model), by_group = TRUE)
```
### Model Summary
```{r}
pp(model);
tbl0 <- gtsummary::tbl_regression(
get(model),
add_pairwise_contrasts = TRUE,
exponentiate = FALSE,
tidy_fun = broom.mixed::tidy,
)
tbl0
```
### Model Parameters
```{r}
pp(model);
parameters::model_parameters(get(model))
```
### FE: Time
```{r}
pp(model);
extra <- "0001"
terms=c("Time")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Period
```{r}
pp(model);
extra <- "0002"
terms=c("Period")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + stuff0
gg88$data$x <- c(2,1,3)
gg88 <- gg88 + scale_x_continuous(breaks=c(1,2,3), labels=c("PB", "PC", "PA"))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Time x Period
```{r}
pp(model);
extra <- "0003"
terms=c("Time", "Period")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + line0 + line1 + stuff0 + rect2
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Outcome
```{r}
pp(model);
extra <- "0004"
terms=c("Outcome")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Time x Outcome
```{r}
pp(model);
extra <- "0005"
terms=c("Time", "Outcome")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + line0 + line1 + stuff0 + rect3
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Period x Outcome
```{r}
pp(model);
extra <- "0006"
terms=c("Period", "Outcome")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88 <- gg88 + stuff0
gg88$data$x <- c(2,1,3) ## CAUTION: THIS WORKS WITH: sjPlot (OR SIMPLER MODEL)
## gg88$data$x <- c(2,2,1,1,3,3) ## CAUTION: THIS WORKS WITH: ggeffects
gg88 <- gg88 + scale_x_continuous(breaks=c(1,2,3), labels=c("PB", "PC", "PA"))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### FE: Time x Outcome x Period
```{r}
pp(model);
extra <- "0007"
terms=c("Time", "Outcome", "Period")
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model), terms=terms, type="eff", show.data=FALSE)
gg88$data$facet <- factor(
case_when(
gg88$data$facet == "PB" ~ "PB",
gg88$data$facet == "PC" ~ "PC",
gg88$data$facet == "PA" ~ "PA",
),
levels=c("PB", "PC", "PA"))
gg88 <- gg88 + line0 + line1 + time0 + stuff0 + rect0
## gg88 <- gg88 + ggplot2::ylim(0.15,0.85)
## gg88 <- gg88 + ggplot2::coord_cartesian(ylim = c(0.25, 0.75))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".png"))
ggsave(file=file, plot=gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-fixed-effects-", paste(terms, collapse="-x-"),".svg"))
ggsave(file=file, plot=gg88, width=8, height=6)
gg88
```
### EF: Time:
#### NULL: Time
```{r}
pp(model);
extra <- "1001"
terms <- c("Time")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Time
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05,)
gg88 <- gg88 + line0 + line1 + time0 + stuff0
## gg88 <- gg88 + coord_cartesian(ylim = c(-0.25, 1.25))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
### EF: Period
#### NULL: Period
```{r}
pp(model);
extra <- "1002"
terms <- c("Period")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Period
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(
limit_range=FALSE,
show_data = FALSE,
dot_alpha = 0.05)
gg88 <- gg88 + stuff0
gg88$data$x <- c(2,1,3)
gg88 <- gg88 + scale_x_continuous(breaks=c(1,2,3), labels=c("PB", "PC", "PA"))
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
#### DIFF: Period
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### EF: Time x Period
#### NULL: Time x Period
```{r}
pp(model);
extra <- "1003"
terms <- c("Period", "Time")
terms <- c("Time", "Period")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Time x Period
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + line0 + line1 + time0 + stuff0 + rect2
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
ggsave(file = "file.svg", plot = gg88, width=8, height=6)
gg88
```
#### DIFF: Time x Period
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.docx"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### EF: Outcome
#### NULL: Outcome
```{r}
pp(model);
extra <- "1004"
terms <- c("Outcome")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Outcome
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
ggsave(file = "file.svg", plot = gg88, width=8, height=6)
gg88
```
#### DIFF: Outcome
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### EF: Time x Outcome:
#### NULL: Time x Outcome
```{r}
pp(model);
extra <- "1005"
terms <- c("Time", "Outcome")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT Time x Outcome
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + line0 + line1 + time0 + stuff0 + rect3
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
#### DIFF: Time x Outcome
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.docx"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### EF: Period x Outcome
#### NULL: Period x Outcome
```{r}
pp(model);
extra <- "1006"
terms <- c("Period", "Outcome")
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Period x Outcome
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
## gg88$data$x <- c(2,1,3) ## CAUTION: THIS WORKS WITH sjPlot (OR SIMPLER MODEL)
gg88$data$x <- c(2,2,1,1,3,3) ## CAUTION: THIS WORKS WITH: ggeffects
gg88 <- gg88 + scale_x_continuous(breaks=c(1,2,3), labels=c("PB", "PC", "PA"))
gg88 <- gg88 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=8, height=6)
gg88
```
#### PLOT: Period x Outcome \[low-level\]
```{r}
pp(model);
extra <- "1006"
terms <- c("Period", "Outcome")
type <- "eff"
type <- "pred"
suppressWarnings(rm(list = ls(pattern = "^gg44")))
gg44 <- sjPlot::plot_model(
get(model),
type = type,
terms = terms,
)
## str(gg44$data)
gg44$data$x <- c(2,2,1,1,3,3)
## gg44 <- gg44 + scale_x_discrete(labels = c("BE", "MI", "ARRR"))
gg44 <- gg44 + scale_x_continuous(
breaks=c(1,2,3),
labels=c("PB", "PC", "PA"))
gg44 <- gg44 + stuff0
file = file.path(dir8, paste0(model,"-xtr-",extra,"-sjplot-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg44, width=8, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-sjplot-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg44, width=8, height=6)
gg44
```
#### DIFF: Period x Outcome
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.docx"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### EF: Time x Period x Outcome
#### NULL: Time x Period x Outcome
```{r}
pp(model);
extra <- "1007"
terms <- c("Time", "Period", "Outcome")
terms <- c("Time", "Outcome", "Period") ## CAUTION
pred0 <- ggeffects::predict_response(get(model), terms=terms)
test0 <- ggeffects::test_predictions(get(model), terms=terms, test=NULL, p_adjust="fdr")
cat0(sep0)
pred0 %>% print(n=Inf)
cat0(sep0)
test0 %>% print(n=Inf)
pred0tab <- ggeffects::print_html(pred0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.html"))
pred0tab %>% tinytable::save_tt(file, overwrite=TRUE)
test0tab <- ggeffects::print_html(test0)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test0.html"))
test0tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
#### PLOT: Time x Period x Outcome
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88$data$facet <- factor(
case_when(
gg88$data$facet == "PB" ~ "PB",
gg88$data$facet == "PC" ~ "PC",
gg88$data$facet == "PA" ~ "PA",
),
levels=c("PB", "PC", "PA"))
gg88 <- gg88 + line0 + line1 + time0 + stuff0
gg88 <- gg88 + rect0
## gg88 <- gg88 + ggplot2::ylim(0.15,0.85)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=12, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=12, height=6)
gg88
```
#### PLOT: Time x Period x Outcome (low-level)
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(
get(model),
type="emm",
terms=terms)
gg88$data$facet <- factor(
case_when(
gg88$data$facet == "PB" ~ "PB",
gg88$data$facet == "PC" ~ "PC",
gg88$data$facet == "PA" ~ "PA",
),
levels=c("PB", "PC", "PA"))
gg88 <- gg88 + line0 + line1 + time0 + stuff0 + rect0
## gg88 <- gg88 + ggplot2::ylim(0.15,0.85)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-sjPlot-", paste(terms, collapse="-x-"),"-pred0.png"))
ggsave(file = file, plot = gg88, width=12, height=6)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-sjPlot-", paste(terms, collapse="-x-"),"-pred0.svg"))
ggsave(file = file, plot = gg88, width=12, height=6)
gg88
```
#### DIFF: Time x Period x Outcome
```{r}
pp(model);
test2 <- ggeffects::test_predictions(get(model), terms=terms, test="pairwise", p_adjust="fdr")
test2 %>% print()
test2tab <- ggeffects::print_html(test2)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.html"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
file = file.path(dir8, paste0(model,"-xtr-",extra,"-ggeffects-", paste(terms, collapse="-x-"),"-test2.docx"))
test2tab %>% tinytable::save_tt(file, overwrite=TRUE)
```
### CHECK: Model Assumptions
```{r}
pp(model);
performance::check_model(get(model))
ggsave(
file = "performance-test.png",
## file.path(dir8, "summary-combined-models.perf0.compare-02-score.png"),
## plot = gg88,
## plot = last_plot(),
width=8,
height=12)
```
```{r}
ggsave(
file = "performance-test.png",
## file.path(dir8, "summary-combined-models.perf0.compare-02-score.png"),
## plot = gg88,
## plot = last_plot(),
width=8,
height=12)
```
```{r}
ls()
```
## Auxiliary Checkups
### Variables influence / importance in fit04aPd
```{r}
## TODO CHANGE TITLE
formula(fit04aPd)
eff_size0 <- effectsize::eta_squared(fit04aPd)
eff_size2 <- eff_size0 %>%
dplyr::mutate(Interpret = effectsize::interpret_eta_squared(Eta2_partial))
performance::print_html(eff_size2)
```
### List models (for Model Hierarchy / Hierarchies)
```{r}
temp <- lapply(ls(pattern="^fit\\d+"), pp)
```
### Compare models using `performance` package with `score`
```{r}
perf0 <- performance::compare_performance(
fit01aPd, # [df0] Agency ~ (1 | Name) + 1
fit02aPd, # [df0] Agency ~ (Time | Name) + Time
fit03aPd, # [df0] Agency ~ (Time | Name) + Time * Period
fit04aPd, # [df0] Agency ~ (Time | Name) + Time * Period * Outcome
## CAUTION: COMMA
rank = TRUE, verbose = FALSE)
perf0 %>% performance::print_html()
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- perf0 %>% plot()
ggsave(
file = file.path(dir8, "summary-combined-models.perf0.compare-02-score.png"),
plot = gg88,
width=8,
height=6)
gg88
```
### Compare less models
```{r}
perf2 <- performance::compare_performance(
## fit01aPd, # [df0] Agency ~ (1 | Name) + 1
## fit02aPd, # [df0] Agency ~ (Time | Name) + Time
fit03aPd, # [df0] Agency ~ (Time | Name) + Time * Period
fit04aPd, # [df0] Agency ~ (Time | Name) + Time * Period * Outcome
## CAUTION: COMMA
rank = TRUE, verbose = FALSE)
perf2 %>% performance::print_html()
suppressWarnings(rm(list = ls(pattern = "^gg44")))
gg44 <- perf2 %>% plot()
ggsave(
file = file.path(dir8, "summary-combined-models.perf2.compare-03-score.png"),
plot = gg44,
width=8,
height=6)
gg44
```
### Comment
Add interpretation of the difference between best fit to data and best predictive power and overfitting (aspecially in the context of the last model).
```{r}
gg44
```
### Performance Table Sorted by R2_conditional
```{r}
perf0 %>% dplyr::arrange(desc(R2_conditional)) %>% performance::print_html()
```
### Performance Table Sorted by R2_marginal
```{r}
perf0 %>% dplyr::arrange(desc(R2_marginal)) %>% performance::print_html()
```
### Interpret R2
```{r}
model <- "fit01aPd" # [df0] Agency ~ (1 | Name) + 1
model <- "fit02aPd" # [df0] Agency ~ (Time | Name) + Time
model <- "fit03aPd" # [df0] Agency ~ (Time | Name) + Time * Period
model <- "fit04aPd" # [df0] Agency ~ (Time | Name) + Time * Period * Outcome
cat0(effectsize::interpret_r2(performance::r2(get(model))$R2_conditional, rules="cohen1988"))
cat0(effectsize::interpret_r2(performance::r2(get(model))$R2_marginal, rules="cohen1988"))
```
### Plot models: Part 1: Basic Models
```{r}
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_models(
## CAUTION the null model can not be used here
## Thus to keep the numbers consistent I have
## used model 02 as an input twice
fit02aPd, # [df0] Agency ~ (Time | Name) + Time
fit02aPd, # [df0] Agency ~ (Time | Name) + Time
fit03aPd, # [df0] Agency ~ (Time | Name) + Time * Period
fit04aPd, # [df0] Agency ~ (Time | Name) + Time * Period * Outcome
spacing=1, dot.size=1
)
ggsave(
file = file.path(dir8, "summary-all-models-part-01.png"),
plot = gg88,
width=5,
height=4)
gg88
```
### Tab Models
The above \`plot_models\` seems to be a lot more illustrative
```{r}
# , eval = TRUE, results='hide'
library(sjPlot)
library(sjmisc)
library(sjlabelled)
tab0 <- sjPlot::tab_model(
fit01aPd, # [df0] Agency ~ (1 | Name) + 1
fit02aPd, # [df0] Agency ~ (Time | Name) + Time
fit03aPd, # [df0] Agency ~ (Time | Name) + Time * Period
fit04aPd, # [df0] Agency ~ (Time | Name) + Time * Period * Outcome
show.reflvl = TRUE,
show.intercept = TRUE,
p.style = "numeric_stars",
file = file.path(dir8, "summary-all-models-part-01-SEE-PNG-images-for-a-better-overview.html"))
tab0
## knitr::html
## papaja::
## rmarkdown::render
## rmarkdown::render(tab0$knitr)
## tab0$knitr
```
### Tabulate models (publication ready)
```{r}
tab0 <- sjPlot::tab_model(
fit01aPd, # [df0] Agency ~ (1 | Name) + 1
fit02aPd, # [df0] Agency ~ (Time | Name) + Time
fit03aPd, # [df0] Agency ~ (Time | Name) + Time * Period
fit04aPd, # [df0] Agency ~ (Time | Name) + Time * Period * Outcome
show.reflvl = FALSE,
show.intercept = TRUE,
p.style = "numeric_stars",
file = file.path(dir8, "summary-all-models-part-02-publication.html"))
tab0
```
```{r}
# save.image(file=file.path(dir8, "session.RData"))
# load(file.path(dir8, "session.RData")
```
### Report
```{r}
result <- report::report(fit04aPd)
```
```{r}
print(result)
```